<?php

namespace app\api\controller;

use app\common\model\Renew;

class RenewController extends BaseApiController
{

    public array $notNeedLogin = ['queryRenew','querySpec','querydisk'];
    public function querySpec()
    {
        $type = $this->request->param('type');
        $specArr = Renew::where('type', $type)->group('spec')->field('spec')->select()->toArray();
        $target_specArr = Renew::where('type', $type)->group('target_spec')->field('target_spec')->select()->toArray();
        return $this->success('查询成功', [

            'spec'        => $specArr,
            'target_spec' => $target_specArr,
        ]);
    }


    public function querydisk()
    {
        $type = $this->request->param('type');
        $spec = $this->request->param('spec');
        $diskArr = Renew::where('type', $type)->where('spec', $spec)->group('disk')->field('disk')->select()->toArray();
        $target_diskArr = Renew::where('type', $type)->where('target_spec', $spec)->group('target_disk')->field('target_disk')->select()->toArray();
        return $this->success('查询成功', [
            'disk'        => $diskArr,
            'target_disk' => $target_diskArr,
        ]);
    }

    public function queryRenew()
    {
        $type = $this->request->param('type');
        $spec = $this->request->param('spec');
        $disk = $this->request->param('disk');
        $screen = $this->request->param('screen');

        $target_spec = $this->request->param('target_spec');
        $target_disk = $this->request->param('target_disk');
        $renew = Renew::where('type', $type)
            ->where('spec', $spec)
            ->where('disk', $disk)
            ->where('screen', $screen)
            ->where('target_spec', $target_spec)
            ->where('target_disk',
            $target_disk)->find();
        if ($renew) {
            return $this->success('查询成功', [
                'diff_price' => $renew['diff_price'] ,
                'old_price' => $renew['old_price'],
                'renew_price' => $renew['renew_price'],

            ]);
        }

        return $this->success('查询成功', [
            'price' => 0,
            'diff_price' => 0,
            'old_price' => 0,
            'renew_price' => 0,
        ]);
    }


}